package com.baixiaowen.xiaoaointerview.Java编程功底篇.手写栈_队列相关算法;

import java.util.LinkedList;

/**
 * 基于LinkedList实现的栈
 *
 * @author Baixiaowen
 */
public class Stack<T> {

    LinkedList<T> list = new LinkedList<>();

    public void push(T e) {
        list.addFirst(e);
    }

    public T pop() {
        return list.pop();
    }

    public int size() {
        return list.size();
    }

    public static void main(String[] args) {
        Stack<Integer> stack = new Stack<>();
        stack.push(1);
        stack.push(2);
        stack.push(3);
        stack.push(4);

        for (int i = stack.size() - 1; i >= 0; i--) {
            if (i + 1 != stack.pop()) {
                System.err.println("成功");
            }
        }
    }

}
